<?php
session_start();

$id = $_GET['id'];

$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : [];

// 查找要删除元素的下标
$index = -1;
for ($i = 0; $i < count($cart); $i++) {
   if ($cart[$i]['id'] == $id) {
      $index = $i;
      break;
   }
}
// 从购物车数组中删除
if ($index > -1) {
    array_splice($cart, $index, 1);
    $_SESSION['cart'] = $cart;
}

header('Location: ../cart.php');
